import pandas as pd
import datetime
import talib
# 数据
data = [['1725702000000', '0.0938', '0.0939', '0.09375', '0.09386', '0'],
        ['1725701700000', '0.0939', '0.09397', '0.0938', '0.0938', '1'],
        ['1725701400000', '0.09375', '0.09391', '0.09375', '0.0939', '1'],
        ['1725701100000', '0.09376', '0.09384', '0.09371', '0.09375', '1'],
        ['1725700800000', '0.09381', '0.09385', '0.09374', '0.09376', '1'],
        ['1725700500000', '0.09393', '0.09396', '0.0938', '0.09381', '1'],
        ['1725700200000', '0.09399', '0.09401', '0.0939', '0.09393', '1'],
        ['1725699900000', '0.09415', '0.09419', '0.09397', '0.09399', '1'],
        ['1725699600000', '0.09427', '0.09435', '0.09407', '0.09415', '1'],
        ['1725699300000', '0.09429', '0.09431', '0.09422', '0.09427', '1'],
        ['1725699000000', '0.09428', '0.09432', '0.09423', '0.09429', '1'],
        ['1725698700000', '0.09439', '0.09443', '0.09421', '0.09428', '1'],
        ['1725698400000', '0.09422', '0.09443', '0.09422', '0.09439', '1'],
        ['1725698100000', '0.09414', '0.0943', '0.09414', '0.09422', '1'],
        ['1725697800000', '0.09434', '0.09447', '0.09409', '0.09414', '1'],
        ['1725697500000', '0.094', '0.09435', '0.094', '0.09434', '1'],
        ['1725697200000', '0.09385', '0.09411', '0.09384', '0.094', '1'],
        ['1725696900000', '0.09403', '0.09422', '0.09385', '0.09385', '1'],
        ['1725696600000', '0.09398', '0.09416', '0.09397', '0.09403', '1'],
        ['1725696300000', '0.09407', '0.09411', '0.09394', '0.09398', '1'],
        ['1725696000000', '0.09399', '0.09418', '0.09394', '0.09407', '1'],
        ['1725695700000', '0.09381', '0.09413', '0.09381', '0.09399', '1'],
        ['1725695400000', '0.09365', '0.09387', '0.09361', '0.09381', '1'],
        ['1725695100000', '0.09396', '0.09409', '0.0936', '0.09365', '1'],
        ['1725694800000', '0.09386', '0.09404', '0.09384', '0.09396', '1'],
        ['1725694500000', '0.09388', '0.09389', '0.09368', '0.09386', '1'],
        ['1725694200000', '0.09414', '0.09437', '0.09384', '0.09388', '1'],
        ['1725693900000', '0.09334', '0.09423', '0.09333', '0.09414', '1'],
        ['1725693600000', '0.09325', '0.09343', '0.09325', '0.09334', '1'],
        ['1725693300000', '0.09326', '0.09332', '0.09316', '0.09325', '1'],
        ['1725693000000', '0.09322', '0.09334', '0.09321', '0.09326', '1'],
        ['1725692700000', '0.09316', '0.0933', '0.09309', '0.09322', '1'],
        ['1725692400000', '0.09322', '0.09333', '0.09309', '0.09316', '1'],
        ['1725692100000', '0.09322', '0.09322', '0.09307', '0.09322', '1'],
        ['1725691800000', '0.09307', '0.09335', '0.09305', '0.09322', '1'],
        ['1725691500000', '0.09317', '0.09324', '0.09307', '0.09307', '1'],
        ['1725691200000', '0.0932', '0.09334', '0.09317', '0.09317', '1'],
        ['1725690900000', '0.0931', '0.09325', '0.0931', '0.0932', '1'],
        ['1725690600000', '0.0932', '0.09324', '0.09308', '0.0931', '1'],
        ['1725690300000', '0.09297', '0.0932', '0.09296', '0.0932', '1'],
        ['1725690000000', '0.09305', '0.09312', '0.09296', '0.09297', '1'],
        ['1725689700000', '0.09303', '0.09318', '0.09295', '0.09304', '1'],
        ['1725689400000', '0.09297', '0.09303', '0.09285', '0.09302', '1'],
        ['1725689100000', '0.09311', '0.09322', '0.09288', '0.09297', '1'],
        ['1725688800000', '0.0931', '0.09321', '0.09307', '0.09311', '1'],
        ['1725688500000', '0.09311', '0.0932', '0.09302', '0.0931', '1'],
        ['1725688200000', '0.09317', '0.09321', '0.09308', '0.09311', '1'],
        ['1725687900000', '0.09334', '0.09341', '0.09316', '0.09317', '1'],
        ['1725687600000', '0.0934', '0.09345', '0.09326', '0.09334', '1'],
        ['1725687300000', '0.09327', '0.09345', '0.09327', '0.0934', '1'],
        ['1725687000000', '0.09292', '0.09329', '0.09292', '0.09327', '1'],
        ['1725686700000', '0.09288', '0.09296', '0.09282', '0.09292', '1'],
        ['1725686400000', '0.09273', '0.09294', '0.09271', '0.09288', '1'],
        ['1725686100000', '0.09312', '0.09321', '0.09271', '0.09273', '1'],
        ['1725685800000', '0.09319', '0.09331', '0.09293', '0.09312', '1'],
        ['1725685500000', '0.0925', '0.09343', '0.0925', '0.09319', '1'],
        ['1725685200000', '0.0925', '0.09256', '0.09234', '0.0925', '1'],
        ['1725684900000', '0.09234', '0.09251', '0.0923', '0.0925', '1'],
        ['1725684600000', '0.0922', '0.09235', '0.09216', '0.09234', '1'],
        ['1725684300000', '0.09216', '0.09223', '0.09213', '0.0922', '1'],
        ['1725684000000', '0.09213', '0.09217', '0.09211', '0.09216', '1'],
        ['1725683700000', '0.09209', '0.09215', '0.092', '0.09213', '1'],
        ['1725683400000', '0.09202', '0.09209', '0.09198', '0.09209', '1'],
        ['1725683100000', '0.09201', '0.09203', '0.09192', '0.09202', '1'],
        ['1725682800000', '0.09205', '0.09207', '0.09196', '0.09201', '1'],
        ['1725682500000', '0.09208', '0.09214', '0.09197', '0.09205', '1'],
        ['1725682200000', '0.09219', '0.09225', '0.09205', '0.09208', '1'],
        ['1725681900000', '0.09212', '0.0922', '0.09209', '0.09219', '1'],
        ['1725681600000', '0.09207', '0.09219', '0.09205', '0.09212', '1'],
        ['1725681300000', '0.09208', '0.09212', '0.09204', '0.09207', '1'],
        ['1725681000000', '0.09214', '0.0922', '0.09203', '0.09208', '1'],
        ['1725680700000', '0.09209', '0.09218', '0.09199', '0.09214', '1'],
        ['1725680400000', '0.09217', '0.09218', '0.09202', '0.09209', '1'],
        ['1725680100000', '0.09213', '0.09223', '0.09211', '0.09217', '1'],
        ['1725679800000', '0.09229', '0.09232', '0.09212', '0.09213', '1'],
        ['1725679500000', '0.09218', '0.09229', '0.09218', '0.09229', '1'],
        ['1725679200000', '0.09213', '0.09229', '0.09208', '0.09218', '1'],
        ['1725678900000', '0.09223', '0.09226', '0.09205', '0.09213', '1'],
        ['1725678600000', '0.09222', '0.0923', '0.09216', '0.09223', '1'],
        ['1725678300000', '0.09228', '0.09233', '0.09216', '0.09222', '1'],
        ['1725678000000', '0.09215', '0.09229', '0.09214', '0.09228', '1'],
        ['1725677700000', '0.09212', '0.09224', '0.09212', '0.09215', '1'],
        ['1725677400000', '0.09216', '0.09234', '0.09211', '0.09212', '1'],
        ['1725677100000', '0.09238', '0.09246', '0.09216', '0.09216', '1'],
        ['1725676800000', '0.09228', '0.09239', '0.09224', '0.09238', '1'],
        ['1725676500000', '0.09215', '0.09234', '0.09214', '0.09228', '1'],
        ['1725676200000', '0.09216', '0.0922', '0.09208', '0.09215', '1'],
        ['1725675900000', '0.09228', '0.09232', '0.09215', '0.09216', '1'],
        ['1725675600000', '0.09212', '0.09235', '0.09212', '0.09228', '1'],
        ['1725675300000', '0.09216', '0.09221', '0.09204', '0.09212', '1'],
        ['1725675000000', '0.0921', '0.09224', '0.0921', '0.09216', '1'],
        ['1725674700000', '0.09192', '0.09214', '0.09191', '0.0921', '1'],
        ['1725674400000', '0.09195', '0.09201', '0.09181', '0.09192', '1'],
        ['1725674100000', '0.09187', '0.09198', '0.09187', '0.09195', '1'],
        ['1725673800000', '0.09184', '0.09196', '0.09176', '0.09187', '1'],
        ['1725673500000', '0.09189', '0.09203', '0.0918', '0.09184', '1'],
        ['1725673200000', '0.09186', '0.09198', '0.09183', '0.09189', '1'],
        ['1725672900000', '0.09194', '0.09208', '0.09186', '0.09186', '1'],
        ['1725672600000', '0.09187', '0.09194', '0.09181', '0.09194', '1'],
        ['1725672300000', '0.09192', '0.09198', '0.09187', '0.09187', '1']]

# 列名
columns = ["timestamp", "open", "high", "low", "close", "confirm"]

# 创建 DataFrame
df = pd.DataFrame(data, columns=columns)

# 转换数据类型
df['open'] = df['open'].astype(float)
df['close'] = df['close'].astype(float)
df['high'] = df['high'].astype(float)
df['low'] = df['low'].astype(float)


df = df.sort_index()

# 计算EMA20
df.sort_index(ascending=False,inplace=True)
df['EMA20'] = talib.EMA(df['close'],timeperiod=20)
df.sort_index(ascending=True,inplace=True)

# 转换时间戳
def convert_timestamp(timestamp):
    timestamp = int(timestamp) / 1000
    dt_object = datetime.datetime.fromtimestamp(timestamp)
    return dt_object.strftime('%Y-%m-%d %H:%M:%S')


df['timestamp'] = df['timestamp'].apply(convert_timestamp)

# 打印转换后的 DataFrame
print(df.head(100))
